import request from '@/utils/request'
import type { ApiResponse } from '@/types/api'

export interface ProfileInfo {
  id: string
  username: string
  phone: string
  balance: number
  status: number
  createTime: string
  updateTime: string
}

export interface UpdateProfileRequest {
  username?: string
  phone?: string
}

export interface UpdatePasswordRequest {
  oldPassword: string
  newPassword: string
}

// 获取个人信息
export const getProfileInfo = () => {
  return request.get<ApiResponse<ProfileInfo>>('/profile/info')
}

// 更新个人信息
export const updateProfile = (data: UpdateProfileRequest) => {
  return request.put<ApiResponse<void>>('/profile/info', data)
}

// 更新密码
export const updatePassword = (oldPw: string, newPw: string) => {
  return request.put<ApiResponse<void>>(`/profile/password?oldPw=${oldPw}&newPw=${newPw}`)
}
